<template>
  <div class="container">
    <el-card style="margin: 20px">
      <el-form :inline="true" style="margin: 0 40px">
        <el-form-item label="一级列表" style="padding: 0 40px">
          <el-select v-model="gory1Id" placeholder="请选择活动区域" @change="category1IdChange(gory1Id)">
            <el-option v-for="item in category1List" :key="item.id" :label="item.name" :value="item.id"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="二级列表" style="padding: 0 40px">
          <el-select
            v-model="gory2Id"
            placeholder="请选择活动区域"
            @change="category2IdChange(gory2Id)"
          >
            <el-option
              v-for="item in category2List"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="三级列表" style="padding: 0 40px">
          <el-select
            v-model="gory3Id"
            placeholder="请选择活动区域"
          >
            <el-option
              v-for="item in category3List"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>
import {mapActions, mapMutations, mapState} from "vuex";

export default {
  name:"Category",
  data(){
    return{
      gory1Id:null,
      gory2Id:null,
      gory3Id:null,
    }
  },
  computed:{
    ...mapState('category',["category1Id","category2Id","category3Id","category1List","category2List","category3List"])
  },
  methods:{
    ...mapActions('category',['getCategory1','getCategory2','getCategory3']),
    ...mapMutations('category',['category1IdChange','category2IdChange'])
  },
  // eslint-disable-next-line vue/order-in-components
  mounted() {
    try {
      this.getCategory1()
    }catch (e){
      this.$message.error(e);
    }
  },
  watch:{
    gory1Id(){
      this.category2Id = null
      this.category3Id = null,
      this.category2List = [],
      this.category3List = []
      this.getCategory2()
    },
    gory2Id(){
      this.category3Id = null,
      this.category3List = []
      this.getCategory3()
    }
  }
}
</script>

<style>
</style>
